package cwiczenia;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;

public class ErrorDisplay extends HttpServlet {

    String[] attributeNames = new String[]{            
            "javax.servlet.error.servlet_name",
            "javax.servlet.error.request_uri",
            "javax.servlet.error.status_code",
            "javax.servlet.error.exception",
            "javax.servlet.error.exception_type",
            "javax.servlet.error.message"
    };

    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException {
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        out.println("<html>");
        out.println("<head>");
        out.println("<title>ErrorDisplay</title>");
        out.println("</head>");
        out.println("<body>");

        for (String attributeName : attributeNames) 
            out.println("<h5>" + attributeName + " = " + request.getAttribute(attributeName) + "</h5>");


        out.println("</body>");
        out.println("</html>");
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException {
        doPost(request, response);
    }
}